<template>
	<view>
		<u-navbar :border-bottom="false" title="设置" :title-size="36" :title-bold="true" :title-color="textColor" :background="{background: bgColor}">
		</u-navbar>
		<view class="u-m-b-20">
			<u-cell-group :border="false">
				<u-cell-item title="个人信息" value="昵称、头像" @click="toPage('profile')"></u-cell-item>
				<!-- <u-cell-item title="手机号" :value="hidePhone(storeUser.phoneNumber)"  @click="toPage('mobile')"></u-cell-item> -->
				<u-cell-item title="手机号" :value="hidePhone(storeUser.phoneNumber)"  @click="$u.toast('该功能正在维护，如需更改请联系客服处理')"></u-cell-item>
				<u-cell-item title="密码" :value="storeUser.hasPassword?'已设置':'未设置'" @click="toPage('password')"></u-cell-item>
				<u-cell-item title="实名认证" :value="storeUser.realPeopleConfirmed?'已实名':'未实名'" :border-bottom="false" @click="toPage('shiming')"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="u-m-b-20" >
			<u-cell-group :border="false">
				<!-- #ifdef APP-PLUS -->
				<u-cell-item title="消息推送" @click="setPermissions"></u-cell-item>
				<!-- #endif -->
				<u-cell-item title="联系客服" @click="toKefu"></u-cell-item>
				<!-- <u-cell-item title="帮助中心"></u-cell-item> -->
				<!-- <u-cell-item title="查看APP版本" @click="toPage('version')"></u-cell-item> -->
				<u-cell-item title="关于我们" @click="toPage('about')"></u-cell-item>
				<u-cell-item title="法律声明" @click="toPage('law')"></u-cell-item>
				<u-cell-item title="清除缓存" :border-bottom="false" @click="clearStorage"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="u-m-b-20" >
			<u-cell-group :border="false">
				<u-cell-item title="注销账号" :border-bottom="false" @click="toPage('zhuxiao')"></u-cell-item>
			</u-cell-group>
		</view>
		<view style="height: 270rpx;"></view>
		<view class="footer">
			<u-button shape="circle" :hair-line="false" :ripple="true" :custom-style="getBtStyle('default', -1, 90)" @click="logout">退出登录</u-button>
		</view>
	</view>
</template>

<script>
	import { useUserStore } from '@/store/user.js';
	import { mapState } from 'pinia';
	export default {
		computed:{
			...mapState(useUserStore, {storeUser: 'user',
				userLogout:'logout',
				updateStatus:'updateStatus'
			})
		},
		methods: {
			// 隐藏手机中间四位
			hidePhone(val) {
				if (val) {
					return val.substr(0, 3) + '****' + val.substr(7)
				} else {
					return ''
				}
			},
			toPage(page) {
				if (page == 'shiming') {
					if (this.storeUser.realPeopleConfirmed) {
						return this.$u.toast('已实名')
					}
				}
				this.$mRouter.push({
					route: '/pages/mine/shezhi/' + page
				})
			},
			clearStorage() {
				this.$u.toast('清除成功', 1000, 'success')
			},
			logout() {
				// this.$store.dispatch('user/logout')
				this.userLogout()
				// this.$store.dispatch('shop/clearShopInfo')
				this.$u.toast('退出成功', 1000, 'success')
				this.$mHelper.getTabbar();
				this.updateStatus(0)
				this.$mHelper.delayedJump('/pages/index/index', 'reLaunch')
			},
			setPermissions() {
				// #ifdef APP-PLUS
				if (plus.os.name == 'Android') { // 判断是Android
					var main = plus.android.runtimeMainActivity();
					var pkName = main.getPackageName();
					var uid = main.getApplicationInfo().plusGetAttribute("uid");
					var NotificationManagerCompat = plus.android.importClass("android.support.v4.app.NotificationManagerCompat");
					//android.support.v4升级为androidx
					if (NotificationManagerCompat == null) {
						NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
					}
					var areNotificationsEnabled = NotificationManagerCompat.from(main).areNotificationsEnabled();
					
					var Intent = plus.android.importClass('android.content.Intent');
					var Build = plus.android.importClass("android.os.Build");
					//android 8.0引导  
					if (Build.VERSION.SDK_INT >= 26) {
						var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
						intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
					} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0  
						var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
						intent.putExtra("app_package", pkName);
						intent.putExtra("app_uid", uid);
					} else { //(<21)其他--跳转到该应用管理的详情页  
						intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
						var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
						intent.setData(uri);
					}
					// 跳转到该应用的系统通知设置页  
					main.startActivity(intent);
					// 未开通‘允许通知’权限，则弹窗提醒开通，并点击确认后，跳转到系统设置页面进行设置  
					// if (!areNotificationsEnabled) {
					// 	uni.showModal({
					// 		title: '通知权限开启提醒',
					// 		content: '您还没有开启通知权限，无法接受到消息通知，请前往设置！',
					// 		showCancel: false,
					// 		confirmText: '去设置',
					// 		success: function(res) {
					// 			if (res.confirm) {
					// 				var Intent = plus.android.importClass('android.content.Intent');
					// 				var Build = plus.android.importClass("android.os.Build");
					// 				//android 8.0引导  
					// 				if (Build.VERSION.SDK_INT >= 26) {
					// 					var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
					// 					intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
					// 				} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0  
					// 					var intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
					// 					intent.putExtra("app_package", pkName);
					// 					intent.putExtra("app_uid", uid);
					// 				} else { //(<21)其他--跳转到该应用管理的详情页  
					// 					intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
					// 					var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
					// 					intent.setData(uri);
					// 				}
					// 				// 跳转到该应用的系统通知设置页  
					// 				main.startActivity(intent);
					// 			}
					// 		}
					// 	});
					// } else {
					// 	this.$u.toast('您已开启消息推送通知权限')
					// }
				} else if (plus.os.name == 'iOS') { // 判断是ISO
					var isOn = undefined;
					var types = 0;
					var app = plus.ios.invoke('UIApplication', 'sharedApplication');
					var settings = plus.ios.invoke(app, 'currentUserNotificationSettings');
					if (settings) {
						types = settings.plusGetAttribute('types');
						plus.ios.deleteObject(settings);
					} else {
						types = plus.ios.invoke(app, 'enabledRemoteNotificationTypes');
					}
					plus.ios.deleteObject(app);
					isOn = (0 != types);
					if (isOn == false) {
						uni.showModal({
							title: '通知权限开启提醒',
							content: '您还没有开启通知权限，无法接受到消息通知，请前往设置！',
							showCancel: false,
							confirmText: '去设置',
							success: function(res) {
								if (res.confirm) {
									var app = plus.ios.invoke('UIApplication', 'sharedApplication');
									var setting = plus.ios.invoke('NSURL', 'URLWithString:', 'app-settings:');
									plus.ios.invoke(app, 'openURL:', setting);
									plus.ios.deleteObject(setting);
									plus.ios.deleteObject(app);
								}
							}
						});
					}
				}
				// #endif  
			}
		}
	}
</script>

<style lang="scss" scoped>
	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: #F8F8F8;
		padding: 30rpx 35rpx 90rpx 35rpx;
		z-index: 99;
	}
</style>
